<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    *{
      margin: 0;
      padding: 0;
    }
    /* 基础样式 */
    .book{
      margin: 10px;
      padding: 15px;
      border: 1px solid #ccc;
    }
    [data-category="科幻"]{
      background-color:#007bff;
      color: white;
    }
       [data-category="历史"]{
      background-color:#8b4513;
      color: #fffdd0;
    }
    [title^="入门"] h2::before{
      content:'🌟';
      margin-right: 5px;
      font-size: 1.2em;  /*  1.2*16  */
    }
  </style>
</head>
<body>
  <div class="book" data-category="科幻">
    <h2>三体</h2>
    <p>作者：刘慈欣</p>
  </div>
  <div class="book" data-category="历史">
    <h2>明朝那些事</h2>
    <p>作者：当年明月</p>
  </div>
  <div class="book" data-category="小说">
    <h2>活着</h2>
    <p>作者：余华</p>
  </div>
  <div class="book" data-category="语言学习" title="入门日语初级课程">
    <h2>日语</h2>
    <p>学习日常对话和基本语法</p>
  </div>
</body>
</html>